/**
* @desc desc
* @author 钱炜亮
* @date 2024-04-21
*/
<template>
  <common-page tab :custom="true">
		<u-navbar
				bgColor="#F7F7F7"
		>
			<block slot="left">
				<view class="page-custom-nav flex" v-if="userType == 2">
					<text class="font-34" style="color: #303030;font-weight: bold;" v-if="!isCompany">{{ companyName }}</text>
					<view class="btn-change flex">
						<image src="../../static/icons/change_user_icon.png" mode="" style="width: 31rpx;height: 25rpx;"></image>
					</view>
					<text class="font-24 color-999" @click="bindChangeUser">{{ !isCompany? '切换个人版': '切换企业版' }}</text>
				</view>
				<view v-else></view>
			</block>
		</u-navbar>
		<view class="page-mine-box">
			<view class="flex justify-between user-wrap" @click="bindGoToUser">
				<view class="flex">
					<image :src="avatar || '../../static/avatar_bg.jpg'" mode="" class="avatar"></image>
					<text class="color-333 font-32 margin-left-38" style="font-weight: bold;">{{ userName }}</text>
				</view>
				<image src="../../static/icons/right_dir_big_icon.png" mode="" style="width: 15rpx;height: 30rpx;"></image>
			</view>
			<view class="info-wrap">
				<view class="item flex justify-between" v-if="isCompany" @click="bingGoToCompany">
					<text class="color-333 font-30" style="font-weight: bold;">我的企业</text>
					<image src="../../static/icons/right_dir_default_icon.png" mode="" style="width: 12rpx;height: 23rpx;"></image>
				</view>
				<view class="item flex justify-between" @click="bindGoToSetting">
					<text class="font-30" style="font-weight: bold;color: #5B5B5B;">设置</text>
					<image src="../../static/icons/right_dir_default_icon.png" mode="" style="width: 12rpx;height: 23rpx;"></image>
				</view>
			</view>
		</view>
		<!-- <u-button text="登出" type="primary" color="#417CE9" class="btn-logout"></u-button> -->
  </common-page>
</template>

<script>
import { mapActions, mapGetters, mapMutations } from 'vuex';
export default {
	data() {
		return {
			// userType: 1, // 0系统用户 1 个人用户 2 企业用户
			isUser: true
		};
	},
	computed: {
		...mapGetters('user',['companyName','isCompany','userName','avatar', 'userType'])
	},
	onLoad() {
		uni.$on('bindUpdateInfo', () => {
			this.getUserInfoData();
		});
		this.getUserInfoData();
	},
	onUnload() {
		uni.$off('bindUpdateInfo');
	},
	methods: {
		...mapActions('user', ['updateUserInfo','setCompany']),
		// 获取公司详情
		async getCompanyInfoData() {
			const [err, result] = await this.$to(uni.$u.http.get('/jeecg-boot/api/v1-public/mini-program-company/companyInfo'));
			if (err) return;
			this.userTitle = result.companyName;
		},
		// 获取用户信息
		async getUserInfoData() {
			const [err, result] = await this.$to(uni.$u.http.get('/jeecg-boot/api/v1-public/mini-program-user/userInfo'));
			if (err) return;
			this.updateUserInfo(result)
		},
		// 改变用户身份
		bindChangeUser() {
			this.setCompany(!this.isCompany)
		},
		// 去修改信息
		bindGoToUser() {
			uni.navigateTo({
				url: `/pages/mine/info`
			});
		},
		// 去我的企业
		bingGoToCompany() {
			uni.navigateTo({
				url: '/pages/mine/company'
			});
		},
		// 去设置
		bindGoToSetting() {
			uni.navigateTo({
				url: '/pages/mine/setting'
			});
		}
		/* ====== S 事件区域 ====== */

		/* ====== E 事件区域 ====== */
		/* ====== S 通用逻辑 ====== */

		/* ====== E 通用逻辑 ====== */
		/* ====== S 接口定义 ====== */

		/* ====== E 接口定义 ====== */
	}
};
</script>

<style lang="scss" scoped>
.page-custom-nav {
	height: 88rpx;
	.btn-change {
		height: 100%;
		width: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 15rpx;
	}
}
.page-mine-box {
	margin-top: 118rpx;
	background-color: #fff;
	border-radius: 20rpx;
	.user-wrap {
		padding: 20rpx 40rpx;
		border-bottom: 1px solid #E3E3E3;
	}
	.avatar {
		width: 103rpx;
		height: 103rpx;
		border-radius: 50%;
	}
	.info-wrap {
		padding: 0 40rpx;
		.item {
			height: 120rpx;
			border-bottom: 1px solid #E3E3E3;
			&:nth-last-of-type(1) {
				border-bottom: none;
			}
		}
	}
}
::v-deep .u-button {
	margin-top: 60rpx;
	border-radius: 80rpx !important;
	.u-button__text {
		font-size: 32rpx !important;
		font-weight: bold;
	}
}
</style>
